using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using Husb.Data;

using CentralOffice.Admin.Data;
using CentralOffice.Admin.DataAccess;
using EmployeeTable = CentralOffice.Admin.Data.EmployeeDataSet.EmployeesDataTable;
using EmployeeRow = CentralOffice.Admin.Data.EmployeeDataSet.EmployeesRow;
using Husb.Security;

namespace CentralOffice.Admin.BusinessActions
{
    public class Employee : DataAccessManager<EmployeeDataSet, EmployeeTable, EmployeeRow, EmployeeAdapter>
    {
        public static EmployeeTable GetEmployeesByDepartmentId(Guid deptId)
        {
            EmployeeTable employees = new EmployeeTable();

            EmployeeTable emp = GetAll();
            foreach (EmployeeRow row in emp.Rows)
            {
                if (row.DepartmentId == deptId && !row.IsDeleted && row.IsActive)
                {
                    employees.ImportRow(row);
                }
            }

            return employees;
        }

        public static EmployeeTable GetEmployeesByDepartmentId(EmployeeTable employees, Guid deptId)
        {
            EmployeeTable tmp = new EmployeeTable();

            if (employees == null)
            {
                employees = GetAll();
            }
            foreach (EmployeeRow row in employees.Rows)
            {
                if (row.DepartmentId == deptId && !row.IsDeleted && row.IsActive)
                {
                    tmp.ImportRow(row);
                }
            }

            return tmp;
        }

        public static MembershipUserEx GetUserByEmployeeId(Guid id)
        {
            List<MembershipUserEx> users = UserManager.GetAllUsersWithEmp(1);

            MembershipUserEx user = users.Find(delegate(MembershipUserEx u) { return u.IsEmployee && u.EmployeeId == id; });
            
            return user;
        }
    }
}
